package com.fortune.service.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.fortune.dal.dao.CreditCardTypeDAO;
import com.fortune.dal.model.CreditCardType;
import com.fortune.service.CreditCardTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CreditCardTypeServiceImpl implements CreditCardTypeService {

    @Autowired
    private CreditCardTypeDAO creditCardTypeDAO ;

    @Override
    public void addCreditCardType(CreditCardType creditCardType) throws BusinessException {
        try{
            creditCardTypeDAO.insert(creditCardType);
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyCreditCardType(CreditCardType creditCardType) throws BusinessException {
        try{
            creditCardTypeDAO.updateById(creditCardType) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public CreditCardType queryCreditCardType(Integer bankId, String cardTypeName) throws BusinessException {
        CreditCardType param = new CreditCardType();
        param.setBankId(bankId);
        param.setName(cardTypeName);
        List<CreditCardType> infos = queryCreditCardTypeList(param) ;
        if(ListUtils.isNotEmpty(infos))  {
            return infos.get(0) ;
        }
        return null;
    }

    @Override
    public CreditCardType queryCreditCardType(Integer creditCardTypeId) throws BusinessException {
        CreditCardType c = null;
        try{
            c = creditCardTypeDAO.queryById(creditCardTypeId) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return c;
    }

    @Override
    public List<CreditCardType> queryCreditCardTypeList(CreditCardType creditCardType) throws BusinessException {
        List<CreditCardType> list = null;
        try{
            list = creditCardTypeDAO.queryByModel(creditCardType) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return list;
    }
}
